package com.hkts.management.common.mq;


import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.io.Serializable;
import java.util.Map;

/**
 * 消息体
 * @author lizhangjun
 */
@Data
public class IMessage implements Serializable
{
    //运单取消
    public static final String CANCEL = "cancel";
    //货主指定司机
    public static final String DRIVER_ASSIGN = "driver_assign";
    //运单确认（报名成功）
    public static final String ORDER_CONFIRM = "order_confirm";
    //货主起草合同
    public static final String DRAWUP_CONTRACT = "drawup_contract";
    //退款成功
    public static final String REFUND = "refund";
    //签订合同成功
    public static final String SIGN_CONTRACT = "sign_contract";
    //司机拒绝合同
    public static final String REFUSED_CONTRACT = "refused_contract";
    //司机上传照片
    public static final String UPLOAD_IMG = "upload_img";
    //司机上传邮寄回单
    public static final String UPLOAD_COURIER = "upload_courier";
    //司机货物已送达
    public static final String CARGO_SUCCESS = "caogo_success";
    //司机催单
    public static final String REMINDER = "reminder";
    //运费已支付
    public static final String FREIGHT_PAY = "freight_pay";
    /**
     * 消息标识id 模板id
     */
    private String messageId;
    /**
     * 消息标识编码
     */
    private String msgCode;

    /**
     * 来源用户id
     */
    private String fromUserId;

    /**
     * 目标用户id
     */
    private String toUserId;


    /**
     * 数据类型
     */
    private Integer mineType;
    /**
     * 发送方式类型
     */
    private Integer chatType;

    /**
     * 消息类型
     */
    private Integer msgType;


    /**
     * 参数
     */
    private Map<String, Object> param;
    /**
     * 携带数据
     */
    private MsgExtras extras;

    public IMessage() {
    }

    public IMessage(Builder builder){
        this.messageId = builder.messageId;
        this.msgCode = builder.msgCode;
        this.fromUserId = builder.fromUserId;
        this.toUserId = builder.toUserId;
        this.mineType = builder.mineType;
        this.chatType = builder.chatType;
        this.msgType = builder.msgType;
        this.param = builder.param;
        this.extras = builder.extras;

    }

    public static class Builder{
        private  String messageId; //必传，默认uuid
        private  String msgCode; //必传，默认uuid
        private String fromUserId;
        private String toUserId;
        private Integer mineType;
        private Integer chatType;
        private Integer msgType;
        private Map<String, Object> param;
        private MsgExtras extras;

        public Builder messageId(String messageId){
            this.messageId = messageId;
            return this;
        }
        public Builder msgCode(String msgCode){
            this.msgCode = msgCode;
            return this;
        }
        public Builder fromUserId(String fromUserId){
            this.fromUserId = fromUserId;
            return this;
        }

        public Builder toUserId(String toUserId){
            this.toUserId = toUserId;
            return this;
        }

        public Builder mineType(Integer mineType){
            this.mineType = mineType;
            return this;
        }
        public Builder chatType(Integer chatType){
            this.chatType = chatType;
            return this;
        }

        public Builder msgType(Integer msgType){
            this.msgType = msgType;
            return this;
        }



        public Builder param(Map<String, Object> param){
            this.param = param;
            return this;
        }
        public Builder extras(MsgExtras extras){
            this.extras = extras;
            return this;
        }

        public IMessage build(){
            return new IMessage(this);
        }

        public String buildStr(){
            return JSON.toJSONString(new IMessage(this));

        }
    }
}
